package main

import (
	"fmt"
	"time"
)

func main() {
	now := time.Now()

	year := now.Year()
	month := now.Month()
	day := now.Day()
	hour := now.Hour()
	minute := now.Minute()
	send := now.Second()

	fmt.Printf("%02d-%02d-%02d %02d:%02d:%02d\n", year, month, day ,hour, minute, send)

	timeStr := now.Format("2006/01/02 15:04:05")
	fmt.Printf("time:%s\n", timeStr)

	//获取当前时间戳
	timestamp := now.Unix()
	fmt.Printf("timestamp is:%d\n", timestamp)

	testTimestamp(timestamp)


	testTicker()
}

/**
  时间戳转Time类型
 */
func testTimestamp(timestamp  int64) {

	timeObj := time.Unix(timestamp, 0)
	year := timeObj.Year()
	month := timeObj.Month()
	day := timeObj.Day()
	hour := timeObj.Hour()
	minute := timeObj.Minute()
	send := timeObj.Second()

	fmt.Printf("current timestamp:%d\n", timestamp)
	fmt.Printf("%02d-%02d-%02d %02d:%02d:%02d\n", year, month, day ,hour, minute, send)
}
/**
  定时器
 */
func testTicker() {
	ticker := time.Tick(1*time.Second)
	for i := range ticker {
		fmt.Printf("%v\n", i)
	}
}